package com.yang.IO;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @Description: TODO
 * @Author: YangTing
 * @Date: 2024-04-26 07:46
 */

public class FileTest {
    public static void main(String[] args) throws IOException {
        File file = new File("hello.txt");
        System.out.println(file.getName());
        System.out.println(file.getAbsolutePath());
        System.out.println(file.getAbsoluteFile());
        System.out.println(file.getParent());
        System.out.println(file.length());
        System.out.println(file.lastModified());

        long timeMillis = System.currentTimeMillis();
        Date date = new Date(timeMillis);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formatDate = format.format(date);
        System.out.println("formatDate = " + formatDate);

        long millis = System.currentTimeMillis();
        Instant instant = Instant.ofEpochMilli(millis);
        LocalDateTime localDateTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        String time = localDateTime.format(formatter);
        System.out.println("time = " + time);

        File file1 = new File("D:\\Java");
        String[] list = file1.list();
        for (String s : list) {
            System.out.println("s = " + s);
        }
        File file2 = new File("C:\\Users\\ASUS\\Desktop\\hello.txt");
        System.out.println("file1.exists() = " + file2.exists());
        boolean isCreate = file2.createNewFile();
        file1.delete();
    }
}
